-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(v2): allow adding components to react-live scope #2826
Conversation
Deploy preview for docusaurus-2 ready! Built with commit 43b6a18 |
packages/docusaurus-theme-live-codeblock/src/theme/CodeBlock/index.js
Outdated
Show resolved
Hide resolved
Just removed the mdx comps from react-live scope @lex111 |
@@ -9,6 +9,7 @@ | |||
"license": "MIT", | |||
"dependencies": { | |||
"@philpl/buble": "^0.19.7", | |||
"@mdx-js/react": "^1.5.8", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer necessary, can we remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
@slorber thanks! |
Is this released already? I'm getting this error:
There is a component defined as
|
@wintercounter I can't tell anything if you don't show anycode, but did you swizzle
We spread I don't think assigning Ui to React is a good idea, you'd rather register the comp explicitly in |
Turns out my file was cached somewhere and it didn't update, seems like it's working now, however, I still get the message.
|
Motivation
Currently, the react-live scope only exposes the React exports, so we can use React, useState etc, but we can't import any other code easily.
If you build a react component library, and want to allow users to play with the components in a live editor, it's important to have a documented way to provide those components in the react-live scope.
See #2807
Test Plan
Dogfooding by using this feature on the Docusaurus website directly
Notes
Swizzling of the react-live scope object is not an ideal solution, as it's global and needs more work from the user, but I think it's good enough to solve the usecase for now.
When we'll have a way to wrap root component, users could use the MDXProvider to reuse the components of the MDX scope for react-live too, instead of swizzling.
Gatsby has a cool feature that permits to make available in react-live scope anything that is imported in the MDX file. Unfortunately, this feature is not so simple to port to Docusaurus (involves extracting imports in mdx string using a babel plugin, writing them to disk etc... see #2807 (comment))